#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<algorithm>
using namespace std;
const int N = 5e4 + 10;
typedef long long ll;
struct node
{
    ll W;
    ll S;
}a[N];
int n;
bool cmp(node& s1, node& s2)
{
    return max(-s1.S, s1.W - s2.S) < max(-s2.S, s2.W - s1.S);
}
int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i].W >> a[i].S;
    }
    sort(a + 1, a + 1 + n, cmp);
    ll ret = -1e9 + 10;
    ll w = 0;
    for (int i = 1; i <= n; i++)
    {
        ret = max(ret, w - a[i].S);
        w += a[i].W;
    }
    cout << ret;
    return 0;
}